package com.example.activity.fragment.game.view

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Paint
import android.view.View
import com.example.activity.R

/**
 * 自定义帽子视图
 */
class HatView(context: Context) : View(context) {
     var bitmapX: Float = 65f
     var bitmapY: Float = 0f

    /**
     * 重写绘制图像
     */
    @SuppressLint("DrawAllocation")
    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        val paint = Paint()
        val bitMap = BitmapFactory.decodeResource(this.resources, R.drawable.hat_01)
        canvas?.drawBitmap(bitMap, bitmapX, bitmapY, paint)

        if (bitMap.isRecycled) {
            //可以回收就回收资源
            bitMap.recycle()
        }
    }

}